The object of this exercise is to find the UUIDs for processes dealing with sugar beet production.

The plan is:

  1. find flows that deal with 'beets'
  2. collect processes mentioned in exchanges that involve those flows

In [1]:
import json
import re

In [2]:
with open('../catalogs/json/ecoinvent_3.2_undefined_xlsx.json') as fp:
    ei32 = json.load(fp)

In [3]:
def search_tags(entity, search):
    """
    This function searches through all the 'tags' (semantic content) of a data set
    and returns 'true' if the search expression is found. case insensitive.
    """
    all_tags = '; '.join([str(x) for x in entity['tags'].values()])
    return bool(re.search(search, all_tags, flags=re.IGNORECASE))

In [4]:
beets = [flow for flow in ei32['flows'] if search_tags(flow,'beet')]

In [5]:
len(beets)


Out[5]:
11

11 beet-related flows


In [6]:
[b['tags']['Name'] for b in beets]


Out[6]:
['sugar beet pulp',
 'sugar beet seed, for sowing',
 'molasses, from sugar beet',
 'harvesting, by complete harvester, beets',
 'fodder beet, Swiss integrated production',
 'sugar beet',
 'sugar, from sugar beet',
 'vinasse, from fermentation of sugar beet molasses',
 'vinasse, from fermentation of sugar beet',
 'fodder beet seed, for sowing',
 'beet seed, Swiss integrated production, for sowing']

In [7]:
beet_processes = [x['process'] for x in ei32['exchanges'] if x['flow'] in beets]

In [8]:
len(beet_processes)


Out[8]:
0

that didn't work... it's because 'beets' is a list of flow objects, but exchange entries only list references to flow objects


In [9]:
beet_refs = [b['dataSetReference'] for b in beets]

In [10]:
beet_processes = [x['process'] for x in ei32['exchanges'] if x['flow'] in beet_refs]

In [11]:
len(beet_processes)


Out[11]:
37

This can include duplicates... set forces the entries to be unique (set members)


In [12]:
len(set(beet_processes))


Out[12]:
31

In [13]:
[p for p in ei32['processes'] if p['dataSetReference'] == beet_processes[0]]


Out[13]:
[{'ReferenceExchange': 'Output: fodder beet, Swiss integrated production',
  'dataSetReference': 'ff4e58d3-09d7-40ac-9f3c-eabaa88af152',
  'entityType': 'process',
  'tags': {'Comment': '',
   'IsicClass': 'Growing of other non-perennial crops',
   'IsicNumber': '0119',
   'Name': 'fodder beet production, Swiss integrated production, intensive',
   'SpatialScope': 'CH',
   'TechnologyLevel': 'Current',
   'TemporalScope': 'interval(1996-01-01, 2003-12-31)'}}]

use pandas to print the processes as a table


In [14]:
import pandas as pd

In [15]:
p_list = [p for p in ei32['processes'] if p['dataSetReference'] in set(beet_processes)]

p_list is a list of full process records -- we want to view all the semantic content of these records -- all the tags


In [16]:
P = pd.DataFrame([p['tags'] for p in p_list], 
                 index=[p['dataSetReference'] for p in p_list])

In [17]:
P


Out[17]:
Comment IsicClass IsicNumber Name SpatialScope TechnologyLevel TemporalScope
bbc75ebc-3664-40b2-890d-e6b2f97a2e84 ConvertedDataset Growing of other non-perennial crops 0119 market for fodder beet, Swiss integrated produ... GLO Undefined interval(2011-01-01, 2011-12-31)
70335b84-9b7e-4d29-9c76-88313377201a ConvertedDataset Liquid and gaseous fuels from biomass 19a ethanol production from sugar beet molasses GLO Current interval(1998-01-01, 2006-12-31)
c866a283-dc26-4703-9d31-4297730cf49d Manufacture of prepared animal feeds 108 market for sugar beet pulp GLO Undefined interval(2012-01-01, 2012-12-31)
801d7ce1-70b3-43ec-a64f-7c5890847854 Seed processing for propagation 0164 market for sugar beet seed, for sowing GLO Undefined interval(1999-01-01, 2002-12-31)
5f176014-6fc0-4dd6-8c39-06128ab92b0a Seed processing for propagation 0164 market for fodder beet seed, for sowing GLO Undefined interval(1999-01-01, 2002-12-31)
e26685b8-4a2b-40a9-8402-fb96b2e76983 Manufacture of prepared animal feeds 108 molasses, from sugar beet, to generic market f... GLO Current interval(2012-01-01, 2012-12-31)
19a6cf49-7787-4a6f-b04e-4604fcd65bec ConvertedDataset Manufacture of sugar 1072 beet sugar production CH Current interval(1998-01-01, 2006-12-31)
5bf47e7e-97f1-42d8-b965-e3216d3c0808 ConvertedDataset Manufacture of sugar 1072 market for molasses, from sugar beet GLO Undefined interval(2011-01-01, 2011-12-31)
28d7d0bb-a809-4d52-b758-375f6cd1b944 ConvertedDataset Liquid and gaseous fuels from biomass 19a ethanol production from sugar beet CH Current interval(2000-01-01, 2004-12-31)
dce659f0-67c0-4912-91dd-7efdd27bde8b ConvertedDataset Support activities for crop production 0161 harvesting, by complete harvester, beets CH Current interval(1991-01-01, 2002-12-31)
897f2d08-936b-4aed-928b-a50dfdfdd802 ConvertedDataset Manufacture of sugar 1072 market for sugar, from sugar beet GLO Undefined interval(2011-01-01, 2011-12-31)
b5b30609-5bcb-4e5b-8dd2-49fe6ef41612 ConvertedDataset Liquid and gaseous fuels from biomass 19a ethanol production from sugar beet GLO Current interval(2000-01-01, 2004-12-31)
da4313db-4cc3-45d1-9885-1075d59e8944 Support activities for crop production 0161 market for vinasse, from fermentation of sugar... GLO Undefined interval(2012-01-01, 2012-12-31)
2d2c62cf-048d-4637-b065-fb638366edb7 Support activities for crop production 0161 field application of vinasse, from fermentatio... GLO Current interval(2000-01-01, 2004-12-31)
33693c3c-c4da-4730-b5e8-adf8f9d60390 Growing of other non-perennial crops 0119 fodder beet production, Swiss integrated produ... GLO Current interval(1996-01-01, 2003-12-31)
d10548bb-9286-4d64-96ab-fbef14c757de ConvertedDataset Seed processing for propagation 0164 beet seed production, Swiss integrated product... GLO Current interval(1999-01-01, 2002-12-31)
2539fa06-23e8-4df1-9a03-635d3ba0545d Support activities for crop production 0161 field application of vinasse, from fermentatio... GLO Current interval(1998-01-01, 2006-12-31)
ae37dbb4-01f2-4ed3-b6fd-94a2addc29c1 ConvertedDataset Support activities for crop production 0161 harvesting, by complete harvester, beets GLO Current interval(1991-01-01, 2002-12-31)
431297af-53f7-46ac-9496-0df5deb29c67 Manufacture of prepared animal feeds 108 sugar beet pulp to generic market for energy feed GLO Current interval(2012-01-01, 2012-12-31)
6fe09e9e-9c61-460a-aec8-aa8c15f84823 ConvertedDataset Growing of cereals (except rice), leguminous c... 0111 market for sugar beet GLO Undefined interval(2011-01-01, 2011-12-31)
2d7074fc-a917-4c55-aa19-a3e2d8b76b32 Support activities for crop production 0161 market for vinasse, from fermentation of sugar... GLO Undefined interval(2012-01-01, 2012-12-31)
64d4ecd3-42ad-470a-845a-7917b060250a ConvertedDataset Seed processing for propagation 0164 beet seed production, Swiss integrated product... CH Current interval(1999-01-01, 2002-12-31)
29106945-7f81-486a-a758-3c6edfc516fa ConvertedDataset Support activities for crop production 0161 market for harvesting, by complete harvester, ... GLO Undefined interval(2011-01-01, 2011-12-31)
b44e89fd-1b6e-472f-b52d-21f0574d2e95 ConvertedDataset Seed processing for propagation 0164 fodder beet seed production, for sowing GLO Current interval(1999-01-01, 2002-12-31)
58873ecd-5b8b-4c3c-b2ee-a4c5178b0c3d Growing of cereals (except rice), leguminous c... 0111 sugar beet production GLO Current interval(1996-01-01, 2003-12-31)
1e4a77d8-ba2e-4292-a904-db1a3861df4a ConvertedDataset Seed processing for propagation 0164 sugar beet seed production, for sowing GLO Current interval(1999-01-01, 2002-12-31)
ff4e58d3-09d7-40ac-9f3c-eabaa88af152 Growing of other non-perennial crops 0119 fodder beet production, Swiss integrated produ... CH Current interval(1996-01-01, 2003-12-31)
96760a85-07a2-41ae-aa58-e6ea0842ea96 Growing of cereals (except rice), leguminous c... 0111 sugar beet production CH Current interval(1996-01-01, 2003-12-31)
33031c6f-9a2b-4a53-badd-44ddbc1a2588 ConvertedDataset Seed processing for propagation 0164 market for beet seed, Swiss integrated product... GLO Undefined interval(2011-01-01, 2011-12-31)
df3186af-bf58-4a1e-b27f-854ede231863 ConvertedDataset Manufacture of sugar 1072 beet sugar production GLO Current interval(1998-01-01, 2006-12-31)
2464cefd-74c2-4446-81c2-f486e7cdda89 ConvertedDataset Liquid and gaseous fuels from biomass 19a ethanol production from sugar beet molasses CH Current interval(1998-01-01, 2006-12-31)

Write this info to a CSV file in the current directory


In [18]:
P.to_csv('beet_processes.csv')

the UUIDs in the index list can be used to identify ecospold XML files to retrieve for further info (including input requirements and exchange values)